#include "calculator.h"
#include <iostream>
#include <cmath>

int Calculator::add(int a, int b) {
    int result = a + b;
    log_operation("add", result);
    return result;
}

int Calculator::subtract(int a, int b) {
    int result = a - b;
    log_operation("subtract", result);
    return result;
}

int Calculator::multiply(int a, int b) {
    int result = a * b;
    log_operation("multiply", result);
    return result;
}

double Calculator::divide(double a, double b) {
    if (b == 0) {
        std::cerr << "Error: Division by zero!" << std::endl;
        return 0.0;
    }
    
    double result = a / b;
    log_operation("divide", result);
    return result;
}

void Calculator::log_operation(const char* operation, double result) {
    std::cout << "Operation: " << operation << " = " << result << std::endl;
}

int factorial(int n) {
    if (n <= 1) {
        return 1;
    }
    return n * factorial(n - 1);
}

int power(int base, int exponent) {
    if (exponent == 0) {
        return 1;
    }
    
    int result = 1;
    for (int i = 0; i < exponent; ++i) {
        result = Calculator().multiply(result, base);
    }
    return result;
}
